import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/Home.vue'
import { Store } from 'vuex'
const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    children:[
      {
        path:'/',
        redirect:'/home'
      },
      {
        path: '/home',
        name: 'HomeSection',
        component: () => import('../views/Pages/HomeSection.vue')
      },   
      {
        path: '/goods',
        name: 'GoodsSection',
        component: () => import('../views/Pages/GoodsSection.vue')
      },   
      {
        path: '/about',
        name: 'AboutSection',
        component: () => import('../views/Pages/AboutSection.vue')
      },  
      {
        path: '/goodslist',
        name: 'GoodsList',
        component: () => import('../views/Pages/GoodsList.vue')
      }, 
      {
        path: '/cate',
        name: 'CateSection',
        component: () => import('../views/Pages/CateSection.vue')
      }, 
      {
        path: '/like',
        name: 'LikeSection',
        component: () => import('../views/Pages/LikeSection.vue')
      }, 
      {
        path: '/orders',
        name: 'Orders',
        component: () => import('../views/Pages/Orders.vue')
      },
      {
        path: '/confirmOrder',
        name: 'confirmOrder',
        component: () => import('../views/Pages/confirmOrder.vue')
      },
    ]
  },
  // {
  //   path: '/about',
  //   name: 'about',
  //   component: () => import('../views/AboutView.vue')
  // }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
const whitePage = ['/goods','/about']

router.beforeEach((to, from, next) => {
  var user_id = localStorage.getItem('user_id');
  if(user_id == ""){
    next('/')
  }else{
    // if( whitePage.indexOf(to.path) != -1 ){
      // next();
    // }else{
      next()
    // }
  }
//   console.log(router.app.$options.store.state.user)
})
export default router
